package com.gismore.demo.config;

import com.gismore.demo.job.HelloProcessor;
import com.gismore.demo.job.HelloReader;
import com.gismore.demo.job.HelloWriter;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by lei on 2017/6/9.
 */
@Configuration
@EnableBatchProcessing
public class BatchConfiguration {

	@Autowired
	private JobBuilderFactory jobs;

	@Autowired
	private StepBuilderFactory steps;

	@Autowired
	private HelloReader helloReader;

	@Autowired
	private HelloProcessor helloProcessor;

	@Autowired
	private HelloWriter helloWriter;

	@Bean("helloJob")
	public Job helloJob(){
		return jobs
				.get("helloJob")
				.preventRestart()
				.start(step1())
				.build();
	}

	@Bean
	protected Step step1() {
		return steps
				.get("step1")
				.<String, String> chunk(10)
				.reader(helloReader)
				.processor(helloProcessor)
				.writer(helloWriter)
				.build();
	}
}
